<?php
class Administrator_Form_Product extends Administrator_Model_Product_View{
	var $id;
	public function __construct($id){
		$this->id = $id;
		$this->lang = new Nguyen_language_system();
		$this->db = Zend_Registry::get('vicdbsystem');
	}
	public function render(){
		$info = '';
		$name = '';
		$store = '';
		$type = '';
		$cat = '';
		$tag = '';
		$manufact = '';
		$price = '';
		$curency = '';
		$salenb = '';
		$salepc = '';
		if($this->id!=''){
			$info = $this->GetProductInfo($this->id);
			$name = $info['name'];
			$store = $info['store'];
			$type = $info['type'];
			$cat = $info['cat'];
			$manufact = $info['manufact'];
			$price = $info['price'];
			$curency = $info['currency'];
			$salenb = $info['salenb'];
			$salepc = $info['salepc'];
			$i=0;
			foreach ($this->GetTagByContent($this->id) as $value) {
				$tagname = $this->GetTagname($value['tag']);
				if($i == 0)$tag .=$tagname;
				$tag .= ','.$tagname;
				$i++;
			}
		}
		echo '<div class="element">';
			echo '<div class="eleft">Tên sản phẩm : </div>';
			echo '<div class="eright"><input type="text" name="name" value="'.$name.'"></div>';
		echo '</div>';
		if($this->id!=''){
			echo '<div class="element">';
				echo '<div class="eleft">Hình ảnh : </div>';
				echo '<div class="eright"><img class="formimg" src="'.$this->ImageUrl('product', $info['image']).'"></div>';
			echo '</div>';
		}
		echo '<div class="element">';
			echo '<div class="eleft">Chọn hình ảnh : </div>';
			echo '<div class="eright">';
				echo '<input type="file" id="image" name="image" >';
			echo '</div>';
		echo '</div>';
		echo '<div class="element">';
			echo '<div class="eleft">Chọn cửa hàng : </div>';
			echo '<div class="eright">';
				echo '<select id="store" name="store" >';
				foreach ($this->GetAllPro_store() as $value) {
					$selected = '';if($store == $value['id'])$selected = ' selected="selected"'; 
					echo '<option'.$selected.' value="'.$value['id'].'">'.$value['name'].'</option>';
				}
				echo '</select>';
			echo '</div>';
		echo '</div>';
		echo '<div class="element">';
			echo '<div class="eleft">Chọn loại sản phẩm : </div>';
			echo '<div class="eright">';
				echo '<select id="type" name="type" >';
				foreach ($this->GetAllProduct_type() as $value) {
					$selected = '';if($type == $value['id'])$selected = ' selected="selected"'; 
					echo '<option'.$selected.' value="'.$value['id'].'">'.$value['name'].'</option>';
				}
				echo '</select>';
			echo '</div>';
		echo '</div>';
?>
<script type="text/javascript">
$('form .sheet .form select#store').change(function(){ 
      $.ajax({
            'url' : '<?php echo BASE_URL.'/administrator/product/rendertypebystore/';?>', // goi den action ajaxcity
            'data': {'storeid':$('form .sheet .form select#store').val()}, 
            'success':function(data){ // sau khi thuc hien thanh cong thi update du lieu vao slbdistrict
               $('form .sheet .form select#type').html(data);
               
            }
      });
});
</script>
<?php 
		echo '<div class="element">';
			echo '<div class="eleft">Chọn loại danh mục : </div>';
			echo '<div class="eright">';
				echo '<select id="cat" name="cat" >';
				foreach ($this->GetAllPro_cat() as $value) {
					$selected = '';if($cat == $value['id'])$selected = ' selected="selected"'; 
					echo '<option'.$selected.' value="'.$value['id'].'">'.$value['name'].'</option>';
				}
				echo '</select>';
			echo '</div>';
		echo '</div>';
?>
<script type="text/javascript">
$('form .sheet .form select#type').change(function(){ 
      $.ajax({
            'url' : '<?php echo BASE_URL.'/administrator/product/rendercatbytype/';?>', // goi den action ajaxcity
            'data': {'typeid':$('form .sheet .form select#type').val()}, 
            'success':function(data){ // sau khi thuc hien thanh cong thi update du lieu vao slbdistrict
               $('form .sheet .form select#cat').html(data);
               
            }
      });
});
</script>
<?php 
		echo '<div class="element">';
			echo '<div class="eleft">Chọn nhà sản xuất : </div>';
			echo '<div class="eright">';
				echo '<select id="manufact" name="manufact" >';
				foreach ($this->GetAllProduct_manufact() as $value) {
					$selected = '';if($manufact == $value['id'])$selected = ' selected="selected"'; 
					echo '<option'.$selected.' value="'.$value['id'].'">'.$value['name'].'</option>';
				}
				echo '</select>';
			echo '</div>';
		echo '</div>';
		echo '<div class="element">';
			echo '<div class="eleft">Giá : </div>';
			echo '<div class="eright"><input type="text" name="price" value="'.$price.'"></div>';
		echo '</div>';
		echo '<div class="element">';
			echo '<div class="eleft">Tiền tệ : </div>';
			echo '<div class="eright">';
			echo '<select id="curency" name="curency" >';
				foreach ($this->GetAllPro_currency() as $value) {
					$selected = '';if($curency == $value['id'])$selected = ' selected="selected"'; 
					echo '<option'.$selected.' value="'.$value['id'].'">'.$value['name'].'</option>';
				}
			echo '</select>';
			echo '</div>';
		echo '</div>';
		echo '<div class="element">';
			echo '<div class="eleft">Khuyến mãi theo giá tiền : </div>';
			echo '<div class="eright"><input type="text" name="salenb" value="'.$salenb.'"></div>';
		echo '</div>';
		echo '<div class="element">';
			echo '<div class="eleft">Khuyến mãi theo (%) : </div>';
			echo '<div class="eright"><input type="text" name="salepc" value="'.$salepc.'"></div>';
		echo '</div>';
		echo '<div class="element">';
			echo '<div class="eleft">Tags : </div>';
			echo '<div class="eright"><input type="text" name="tag" value="'.$tag.'"></div>';
		echo '</div>';
		?>
<script type="text/javascript">

</script>
	<?php }
}